package net.neiquan.applibrary.base;

import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;

import net.neiquan.applibrary.R;
import net.neiquan.applibrary.pulltorefresh.PullToRefreshRecyclerView;

/**
 * Created by wl_user on 2017/7/11.
 */

public abstract class BaseListActivity extends BaseActivity implements PullToRefreshRecyclerView.OnRefreshListener2 {
    protected int pageNum = 1;
    protected static int PAEG_SIZE = 10;
    protected View view;
    protected BaseMultiItemQuickAdapter adapter;
    RelativeLayout mHeadView;
    private PullToRefreshRecyclerView mRecylerView;

    @Override
    public int getRootViewId() {
        return R.layout.base_common_xlistview;
    }

    @Override
    public void setViews() {
        mRecylerView = (PullToRefreshRecyclerView) findViewById(R.id.mRecylerView);
        mHeadView = (RelativeLayout) findViewById(R.id.head_view);
        setAdapter();
    }

    private void setAdapter() {
        setHeadView(isHaveHead());
        setHeadViews();
        adapter = getAdapter();
        mRecylerView.getRefreshableView().setAdapter(adapter);
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getLineNum() == 0 ? 1 : getLineNum(),
                StaggeredGridLayoutManager.VERTICAL);
        layoutManager.setOrientation(StaggeredGridLayoutManager.VERTICAL);
        mRecylerView.getRefreshableView().setLayoutManager(layoutManager);
    }

    protected abstract boolean isHaveHead();

    /**
     * 当返回为true时候设置
     */
    protected abstract void setHeadViews();

    private void setHeadView(boolean isHaveHead) {
        if (!isHaveHead) {
            mHeadView.setVisibility(View.GONE);
        } else {
            mHeadView.setVisibility(View.VISIBLE);
        }
    }

    protected abstract BaseMultiItemQuickAdapter getAdapter();

    protected abstract int getLineNum();

}
